package top.zhangjianyong.tools;

import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.alibaba.fastjson.JSONObject;

import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author ： zhangjianyong
 * @date ： 2022/12/9 7:19 PM
 */
public class ExcelIdCard {

    public static void main(String[] args) {
        File file = new File("/Users/zhangjianyong/Desktop/副本星洲60岁以上老年人接种新冠疫苗情况统计表1.xlsx");
        ExcelReader reader = ExcelUtil.getReader(file, "Sheet2");
        List<Map<String, Object>> list = reader.readAll();

        list.stream().forEach(map -> {
            String id = (String) map.get("身份证号码");
            id=id.substring(6, 14);
            int n = Integer.parseInt(id);
            if (n <= 19421210) {//>80
                map.put("年龄", "大于80");
            } else if (n <= 19621210 && n > 19421210) {//60-79
                map.put("年龄", "60-79");
            } else {
                map.put("年龄", "小于60");
            }
        });

        ExcelWriter sheet3 = ExcelUtil.getWriter(file, "Sheet3");
        sheet3.write(list).flush().close();

    }

    public void test() {
        File file = new File("/Users/zhangjianyong/Desktop/副本星洲60岁以上老年人接种新冠疫苗情况统计表1.xlsx");
        ExcelReader reader = ExcelUtil.getReader(file, "Sheet2");
        List<Map<String, Object>> list = reader.readAll();

        long count1 = list.stream()
                .map(map -> (String) map.get("身份证号码"))
                .map(s -> s.substring(6, 14))
                .map(s -> Integer.parseInt(s))
                .filter(n -> n <= 19421210)
                .count();//大于80

        long count2 = list.stream()
                .map(map -> (String) map.get("身份证号码"))
                .map(s -> s.substring(6, 14))
                .map(s -> Integer.parseInt(s))
                .filter(n -> n <= 19621210 && n > 19421210)
                .count();//小于80

        long count3 = list.stream()
                .map(map -> (String) map.get("身份证号码"))
                .map(s -> s.substring(6, 14))
                .map(s -> Integer.parseInt(s))
                .filter(n -> n > 19621210)
                .count();//小于80


        System.out.println(count1);
        System.out.println(count2);
        System.out.println(count3);
    }
}
